package com.si3.controlador;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;
import org.springframework.web.servlet.view.RedirectView;

import com.si3.modelo.Login;
import com.si3.modelo.Solicitud;
import com.si3.modelo.Usuario;
import com.si3.servicio.SolicitudesService;

public class ViewSolicitudController extends AbstractController{

	private SolicitudesService solicitudesService;
	
	public ViewSolicitudController()
	{
	}
	
	public SolicitudesService getSolicitudesService()
	{
	    return solicitudesService;
	}
	
	public void setSolicitudesService(SolicitudesService solicitudesService)
	{
	    this.solicitudesService = solicitudesService;
	}
	
	
	protected ModelAndView handleRequestInternal(
	        HttpServletRequest request,
	        HttpServletResponse response) throws Exception
	{	   
		ModelAndView mv;	        
	    mv = new ModelAndView("viewSolicitud");   
		String codigo = request.getParameter("codigo"); 
	    Login login = (Login) request.getSession().getAttribute("login");
	    if (login.getUserType() == Usuario.TipoUsuario.ADMIN)
	    {
	      Solicitud solicitud=solicitudesService.getSolicitud(Integer.parseInt(codigo));
	      mv.addObject("solicitud",solicitud);        
	    }
	    return mv;
	}
}